﻿using AutoMapper;
using WeatherHistory.Api.CommandsQueries.Mapping;
using WeatherHistory.Data.Entities;
using WeatherHistory.Shared.Extensions;

namespace WeatherHistory.Api.CommandsQueries.Queries.Weathers.GetLast;

public class GetLastWeathersQueryResponse : IMapWith<Weather>
{
    /// <summary>
    ///     Идентификатор региона
    /// </summary>
    public long Id { get; set; }
    public string RegionName { get; set; } = null!;
    public float Temperature { get; set; }
    public float Humidity { get; set; }
    public float WindSpeed { get; set; }
    public string WeatherCondition { get; set; } = null!;
    public float PrecipitationAmount { get; set; }
    public string MeasurementDateTime { get; set; } = null!;
    public List<long> WeatherForecast { get; set; } = null!;

    public void Mapping(Profile profile)
    {
        profile.CreateMap<Weather, GetLastWeathersQueryResponse>()
            .ForMember(dest => dest.Id,
                opt => opt.Ignore())
            .ForMember(dest => dest.RegionName,
                opt => opt.Ignore())
            .ForMember(dest => dest.Temperature,
                opt => opt.MapFrom(src => src.Temperature))
            .ForMember(dest => dest.Humidity,
                opt => opt.MapFrom(src => src.Humidity))
            .ForMember(dest => dest.WindSpeed,
                opt => opt.MapFrom(src => src.WindSpeed))
            .ForMember(dest => dest.WeatherCondition,
                opt => opt.MapFrom(src => src.WeatherCondition))
            .ForMember(dest => dest.PrecipitationAmount,
                opt => opt.MapFrom(src => src.PrecipitationAmount))
            .ForMember(dest => dest.MeasurementDateTime,
                opt => opt.MapFrom(src => src.MeasurementDateTime.ToIso8601String()))
            .ForMember(dest => dest.WeatherForecast,
                opt => opt.MapFrom(src => src.Forecasts.Select(x => x.Id)));
    }
}